package com.my.handler;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.handler.codec.http.*;

/**
 * @author WangLuoXin
 * &#064;Date 2024/9/20  14:25
 * 前置预处理器
 **/
public class PreProcessorsHandler extends SimpleChannelInboundHandler<FullHttpRequest> {

    @Override
    protected void channelRead0(ChannelHandlerContext ctx, FullHttpRequest req) throws Exception {
        if (HttpUtil.is100ContinueExpected(req)) {
            ctx.write(new DefaultFullHttpResponse(
                    HttpVersion.HTTP_1_1,
                    HttpResponseStatus.CONTINUE));
            return;
        }
        String uri = req.uri();
        if (uri.contains("favicon.ico")) {
            return;
        }
        ctx.fireChannelRead(req.retain());
    }
}
